package controller

import (
	"user-center/dto"
	"user-center/query"
	"user-center/service"

	"github.com/androidsr/sc-go/model"
	"github.com/androidsr/sc-go/sgin"
	"github.com/gin-gonic/gin"
)

func init() {
	sgin.AddRouter(SysPermissionController{
		sysPermissionService: service.NewSysPermissionService(),
	})
}

type SysPermissionController struct {
	sysPermissionService service.SysPermissionService
}

// 查询
// @Router [get] [/syspermission/:id]
func (m SysPermissionController) Get(c *gin.Context) any {
	id := c.Param("id")
	if id == "" {
		return model.NewFailDefault("ID不能为空")
	}
	return m.sysPermissionService.Get(id)
}

// 增加
// @Router [post] [/syspermission]
func (m SysPermissionController) Save(c *gin.Context, dto *dto.SysPermissionDTO) any {
	dto.Id = ""
	return m.sysPermissionService.Save(dto)
}

// 修改
// @Router [put] [/syspermission/edit]
func (m SysPermissionController) UpdateById(c *gin.Context, dto *dto.SysPermissionDTO) any {
	if dto.Id == "" {
		return model.NewFailDefault("ID不能为空")
	}
	return m.sysPermissionService.UpdateById(dto)

}

// 删除
// @Router [delete] [/syspermission/:id]
func (m SysPermissionController) DeleteById(c *gin.Context) any {
	id := c.Param("id")
	if id == "" {
		return model.NewFailDefault("ID不能为空")
	}
	return m.sysPermissionService.DeleteById(id)
}

// 查询列表
// @Router [post] [/syspermission/page]
func (m SysPermissionController) QueryPage(c *gin.Context, query *query.SysPermissionQueryDTO) any {
	return m.sysPermissionService.QueryPage(query)
}

// 分页下拉
// @Router [post] [/syspermission/list]
func (m SysPermissionController) QuerySelect(c *gin.Context, query *model.SelectQueryDTO) any {
	return m.sysPermissionService.QueryList(query)
}
